<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script type="text/javascript">
      const _shallowClone = (target) => {
        // 补全代码
        //判断target数据类型
        /* 方法一： */
        if (typeof target === 'Object' && target !== null) {
          let str = Object.prototype.toString.call(target)
          if (str == '[object Date]' || str == '[object RegExp]' || str == '[object Function]') {
            return target
          } else {
            let result = Array.isArray(target) ? [] : {}
            for (prop in target) {
              result[prop] = target[prop]
            }
            return result
          }
        } else {
          return target
        }
        /* 方法二： */
        // return Object.assign({}, target)
      }

      console.log(
        _shallowClone({
          usrname: '张三',
          age: 90,
        })
      )
    </script>
  </body>
</html>
